package com.youku.plugins.feedback
{
   import flash.display.Sprite;
   import flash.text.TextField;
   import flash.utils.Timer;
   import flash.text.TextFormat;
   import com.youku.utils.Tweener;
   import flash.events.TimerEvent;
   import com.youku.utils.AssetUtil;
   import com.youku.skin.YaheiFontManager;
   import flash.text.TextFormatAlign;
   
   public class Feedback extends Sprite
   {
      
      public function Feedback() {
         super();
         this._layer = new Sprite();
         this.addChild(this._layer);
         this._background = AssetUtil.getAsset("V4_panel_bg") as Sprite;
         this._layer.addChild(this._background);
         this._textFormat = new TextFormat(YaheiFontManager.MICROSOFT_YAHEI,16,16777215);
         this._textFormat.align = TextFormatAlign.CENTER;
         this._textField = new TextField();
         this._textField.defaultTextFormat = this._textFormat;
         this._textField.selectable = false;
         this._textField.width = 35;
         this._textField.height = 25;
         this._textField.y = 5;
         this._textField.cacheAsBitmap = true;
         this._layer.alpha = 0;
         this._layer.visible = false;
         this._layer.addChild(this._textField);
         this._timer = new Timer(this._interval,1);
         this._timer.addEventListener(TimerEvent.TIMER_COMPLETE,this.onTimeout);
         this.mouseEnabled = false;
      }
      
      private var _layer:Sprite;
      
      private var _background:Sprite;
      
      private var _textField:TextField;
      
      private var _tweenSpeed:Number = 0.5;
      
      private var _timer:Timer;
      
      private var _interval:Number = 2000.0;
      
      private var _textFormat:TextFormat;
      
      private var _text:String = "  ";
      
      private var _width:Number = 500;
      
      private var _height:Number = 300;
      
      private var _isFullScreen:Boolean = false;
      
      private var _isShow:Boolean = false;
      
      public function show(param1:String) : void {
         this._text = param1;
         this._background.width = this.getTextWidth(this._text) + 30;
         this._background.width = this._background.width < 85?85:this._background.width;
         this._background.height = 35;
         this._textField.width = this._background.width;
         this._textField.text = param1;
         this.layout(this._width,this._height,this._isFullScreen);
         if(!this._isShow)
         {
            Tweener.to(this._layer,this._tweenSpeed,{"alpha":1});
         }
         this._timer.reset();
         this._timer.start();
         this._layer.visible = true;
         this._isShow = true;
      }
      
      public function layout(param1:Number, param2:Number, param3:Boolean) : void {
         this._width = param1;
         this._height = param2;
         this._isFullScreen = param3;
         var _loc4_:Number = 1;
         var _loc5_:Number = 0;
         if(this._isFullScreen)
         {
            _loc4_ = param2 / 600;
         }
         this._layer.scaleX = this._layer.scaleY = _loc4_;
         this._layer.x = (this._width - this._layer.width) / 2;
         this._layer.y = param2 - this._layer.height - 116 * _loc4_;
         if(this._layer.y < (param2 - this._layer.height) / 2)
         {
            this._layer.y = (param2 - this._layer.height) / 2;
         }
         this._layer.x = int(this._layer.x);
         this._layer.y = int(this._layer.y);
         this._layer.width = int(this._layer.width);
         this._layer.height = int(this._layer.height);
      }
      
      private function onTimeout(param1:TimerEvent) : void {
         this.hide();
      }
      
      private function hide() : void {
         this._isShow = false;
         Tweener.to(this._layer,this._tweenSpeed,
            {
               "alpha":0,
               "onComplete":this.onComplete
            });
      }
      
      private function onComplete() : void {
         this._layer.visible = false;
      }
      
      private function getTextWidth(param1:String) : Number {
         var _loc2_:TextField = new TextField();
         _loc2_.defaultTextFormat = this._textFormat;
         _loc2_.width = 1000;
         _loc2_.text = param1;
         return _loc2_.textWidth;
      }
   }
}
